package gen;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Generator {
	public static void main(String[] args) {
		String dburl = "jdbc:mysql://localhost:3306/test?useSSL=false&characterEncoding=utf8&serverTimezone=UTC&allowPublicKeyRetrieval=true";
		String dbusername = "root";
		String dbpassword = "xjc123465";
		String packageName = "com.sit.jike.hrproject";
		String path = "d:/temp/out";


//		List<String> tableList = Arrays.asList("base_org", "sys_menu", "sys_role", "sys_role_menu_rel", "sys_user",
//				"sys_user_org_rel", "sys_user_role_rel");

		List<String> tableList = Arrays.asList("hr_dept","drug");

		FastAutoGenerator.create(
				new DataSourceConfig.Builder(dburl, dbusername, dbpassword)
						.dbQuery(new MySqlQuery()).typeConvert(new MySqlTypeConvert())
						.keyWordsHandler(new MySqlKeyWordsHandler()))
				.globalConfig(builder -> {
					builder.author("Allen") // 设置作者
							.outputDir(path); // 指定输出目录
				}).packageConfig(builder -> {
					builder.parent(packageName) // 设置父包名
							.moduleName("") // 设置父包模块名
							.pathInfo(Collections.singletonMap(OutputFile.xml,
									path + "/mapper")); // 设置mapperXml生成路径
				}).strategyConfig(builder -> {
					builder.addInclude(tableList) // 设置需要生成的表名
							.addTablePrefix("t_", "c_"); // 设置过滤表前缀
				})
				.execute();
	}
}
